﻿/************************************************************************************
* Copyright (c) 2019 All Rights Reserved.
*命名空间：Separate.Model
*文件名： Vision
*创建人： Liebeskind
*创建时间：2019/6/17 11:17:54
*描述
*=====================================================================
*修改标记
*修改时间：2019/6/17 11:17:54
*修改人：Liebeskind
*描述：
************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HalconDotNet;
using PylonCamera;

namespace Separate.Model.Vision
{
    /// <summary>
    /// 视觉结果枚举：1.有产品且产品正常；2.有产品但产品异常；3.无产品视为封盖
    /// </summary>
    public enum VisionResult
    {
        Pass,
        Fail,
        /// <summary>
        /// 封盖
        /// </summary>
        Vacancy
    };
    public class Camera
    {
        public static void CameraInit()
        {
            CameraA = new CPylonCamera();
            CameraB = new CPylonCamera();
        }
        public static CPylonCamera CameraA;
        public static CPylonCamera CameraB;
        public static void DispObj(HObject ho_Image, ref HWindowControl hw)
        {
            HTuple hv_Width = null, hv_Height = null;
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
            HOperatorSet.SetPart(hw.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
            HOperatorSet.ClearWindow(hw.HalconWindow);
            HOperatorSet.DispObj(ho_Image, hw.HalconWindow);
            ho_Image.Dispose();
        }
        public static HObject GrabOnePic_StaticA()
        {
            HObject ho_Image;
            HOperatorSet.GenEmptyObj(out ho_Image);
            CameraA.GrabOnePic(out ho_Image);
            return ho_Image;
        }
        public static HObject GrabOnePic_StaticB()
        {
            HObject ho_Image;
            HOperatorSet.GenEmptyObj(out ho_Image);
            CameraA.GrabOnePic(out ho_Image);
            return ho_Image;
        }
        public static Func<HObject> GrabOnePic_AsyncA = new Func<HObject>(GrabOnePic_StaticA);
        public static Func<HObject> GrabOnePic_AsyncB = new Func<HObject>(GrabOnePic_StaticB);

    }
}
